<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/admin/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>添加用户页面</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<link rel="stylesheet" type="text/css" href="../css/backCss.css">
<link rel="stylesheet" href="../css/register.css" type="text/css" /> 
</head>
<script type="text/javascript"> 
	function check(){ 
		userID = document.getElementById("userID").value ;
		if(userID.lenght<=0){
			alert("用户名不能为空"); 
			return false;
		}else{
			if(!(userID.length>=6&&userID.length<=30)){
				alert("用户名长度在6-30之间"); 
				return false;
			} 
		}
		
		password = document.getElementById("password").value ;
		var rePassword = document.getElementById("rePassword").value ;
		
		if(!(password.length>=6&&password.length<=30)){
			alert("输入的密码不合理"); 
			return false;
		}else{
			if(password!=rePassword){
				alert("两次输入的密码不一致");
				return false;
			} 
		}
		  
		email = document.getElementById("email").value ;
		var reEmail = document.getElementById("reEmail").value ;
	
		if(!isEmail(email)){
			alert("邮箱地址输入不合法"); 
			return false;
		}else{
			if(email!=reEmail){
				alert("两次输入的邮箱地址不一致");
				return false;
			}
		} 
		
		name = document.getElementById("name").value ;

		sex = document.getElementById("sex").value ; 
 
	}
	
	function submitRegister(){ 
		return check();
	}


	function checkUserID(uid){
		userID = uid.value;
		if(userID.lenght<=0){
			document.getElementById("userIDSpan").innerHTML = "<font color='red'>×用户名不能为空</font>"; 
			return false;
		}else{
			if(!(userID.length>=6&&userID.length<=30)){ 
				document.getElementById("userIDSpan").innerHTML = "<font color='red'>×用户名长度在6-30之间</font>";
				return false;
			} else{
				document.getElementById("userIDSpan").innerHTML = "<font color='green'>√正确</font>";
				return true;
			}
		}
	}
	
	function checkPassword(pw){
		password = pw.value;
		if(password.length>=6&&password.length<=30){
			document.getElementById("passwordSpan").innerHTML = "<font color='green'>√正确</font>";
		}else{
			document.getElementById("passwordSpan").innerHTML = "<font color='red'>×密码由6-30位字符组成</font>";
		}
	}

	function checkRePassword(rePw){  
		var val = rePw.value;
		if(password!=val){
			document.getElementById("rePasswordSpan").innerHTML = "<font color='red'>×两次输入的密码不一致</font>";
		}else{
			if(val.length>=6&&val.length<=30){
				document.getElementById("rePasswordSpan").innerHTML = "<font color='green'>√正确</font>";
			}else{ 
				document.getElementById("rePasswordSpan").innerHTML = "<font color='red'>×密码由6-30位字符组成</font>";
			}
		}
	}  

	// 校验是否是Email
	function isEmail(eml) { 
		var re = new RegExp("@[\\w]+(\\.[\\w]+)+$");
		return (re.test(eml)); 
	}

	
	function checkEmail(e_mail) {
		email = e_mail.value;
		if(isEmail(email)){
			document.getElementById("emailSpan").innerHTML = "<font color='green'>√正确</font>";
		}else{
			document.getElementById("emailSpan").innerHTML = "<font color='red'>×电子邮箱地址不合法</font>";
		}
	}

	function checkReEmail(re_e_mail) {
		var val = re_e_mail.value;
		if(isEmail(val)){
			if(email!=val){
				document.getElementById("reEmailSpan").innerHTML = "<font color='red'>×两次输入邮箱地址不一致</font>";
			}else{
				document.getElementById("reEmailSpan").innerHTML = "<font color='green'>√正确</font>";
			}
		}else{
			document.getElementById("reEmailSpan").innerHTML = "<font color='red'>×电子邮箱地址不合法</font>";
		}
	}
	
	var userID="";
	var password="";
	var email="";
	var name="";
	var sex=0;  
</script>
<script src="../js/calendar3.js" type="text/javascript"></script> 
  
  <body>
   	
   	<div class="top"  align="center" >
		<jsp:include page="top.jsp"></jsp:include>
	</div>
	
	<div class="content"  align="center" >
   	   <div class="zt_b">
				<form action="addUser.action" method="post" name="form1"
					onsubmit="return submitRegister();">
					<ul>
						<li>
							<span class="zc_name"> 用户名/ID<font color="red">*</font> </span>
							<input type="text" class="zc_text" id="userID" name="user.userID"
								value="" onblur="checkUserID(this)" />
							<span class="zc_tip" id="userIDSpan">
								中、英文、数字均可(注：用户名注册后不能更换)</span>
						</li>

						<li>
							<span class="zc_name"> 输入密码<font color="red">*</font> </span>
							<input type="password" class="zc_text" id="password"
								name="user.password" value=""
								onblur="checkPassword(this)" />
							<span class="zc_tip" id="passwordSpan">
								由6-30位字符组成，请使用英文字母、符号或数字。</span>
						</li>

						<li>
							<span class="zc_name"> 再次输入密码<font color="red">*</font> </span>
							<input type="password" class="zc_text" id="rePassword"
								name="rePassword" onblur="checkRePassword(this)" />
							<span class="zc_tip" id="rePasswordSpan">
								为了确保您输入的密码正确，请再次输入密码</span>
						</li>

						<li>
							<span class="zc_name"> 电子邮件<font color="red">*</font> </span>
							<input type="text" class="zc_text" id="email" name="user.email"
								value="" onblur="checkEmail(this)" />
							<span class="zc_tip" id="emailSpan">
								非常重要！这是找回密码的首选方式，请务必填写正确</span>
						</li>

						<li>
							<span class="zc_name"> 确认电子邮件<font color="red">*</font> </span>
							<input type="text" class="zc_text" id="reEmail" name="reEmail"
								onblur="checkReEmail(this)" />
							<span class="zc_tip" id="reEmailSpan"> 请再输入一遍上面输入的电子邮件地址</span>
						</li>

						<li>
							<span class="zc_name"> 真实姓名 </span>
							<input type="text" class="zc_text" id="name" name="user.name"
								value="" />
							<span class="zc_tip" id="nameSpan"> </span>
						</li>

						<li>
							<span class="zc_name"> 用户性别</span>
							<span class="zc_text"> <select name="sex" id="sex"
									class="zc_sel">
									<option value="1">
										男
									</option>
									<option value="0">
										女
									</option>
								</select> </span>
							<span class="zc_tip" id="sexSpan"></span>
						</li>

						<li>
							<span class="zc_name"> 用户身份</span>
							<span class="zc_text"> <select name="user.identity"
									id="identity" style="width: 80px;">
									<option value="1">
										普通用户
									</option>
									<option value="0">
										管理员
									</option>
								</select> </span>
							<span class="zc_tip" id="sexSpan"></span>
						</li>

						<li>
							<span class="zc_name"> 出生日期 </span>
							<input class="zc_text" type="text" id="control_date"
								name="user.birthday" value=""
								onclick="new Calendar().show(this);" readonly="readonly" />
							<span class="zc_tip" id="birthdaySpan"> <span
								class="zc_service"> </span> </span>
						</li>
						<li>
							<span class="zc_name"> </span>
							<span class="zc_xz"> 
									<input type="submit" value=" 添 加 "
									style="background: #E6F5FF;"> 
									<input type="button"
									value=" 返 回 " style="background: #E6F5FF;"
									onclick="history.go(-1)"> </span>
						</li>
					</ul>
				</form>
			</div>
   	 </div>
	
	<div class="foot"  align="center" > 
		<jsp:include page="foot.jsp"></jsp:include>		
	</div>
  </body>
</html>
